/**   
 * @Title: DateConvert.java 
 * CopyRight(c)2010-DMX 
 */
package com.dmx.fw.component.util;

import java.text.SimpleDateFormat;

import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;


/** 
 * @Description: 日期格式转换，目标格式yyyy-MM-dd
 * @author: system
 * @date: 2006
 * @version V1.0 
 * 
 */
public class DateConvert implements Converter {
	
	/** 
	 * @Fields df：转换目标格式
	 */
	 private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// HH:mm:ss
	 
	 /** 
	  * <p>Description: default constructor</p> 
	  */	 
	 public DateConvert(){}  
	 
	 /**
	  * @Description 转换日期
	  * @param type: 
	  * @param value: 源对象String
	  * @return Object
	  * @throws ConversionException
	  */
	 public Object convert(Class type, Object value){
	  if(value==null) return null;    
	  if(String.class.isAssignableFrom(value.getClass()) && ((String)value).trim().length()>0){ 
		  try {       
			  return df.parse((String)value);      
		  }catch (Exception ex) {
			  throw new ConversionException("输入的日期类型不合乎yyyy-MM-dd" + value.getClass());      
		  }    
	  }else{   
	      return value;
	  }  
	}
}
